package socket1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    private ServerSocket serverSocket;
    public Server(){
        try {
            System.out.println("服务器开启");
          serverSocket = new ServerSocket(8083);
            System.out.println("服务器已开启");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public  void start(){
        try {
            System.out.println("正在等待连接");
            Socket socket =serverSocket.accept();
            System.out.println(socket.getInetAddress().getHostAddress()+"已连接");

            InputStream is = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String len;
            while ((len = br.readLine())!=null){
                System.out.println(socket.getInetAddress().getHostAddress()+"说"+len);
            }


        } catch (IOException e) {
            e.printStackTrace();
        }





    }
    public static void main(String[] args) {
        Server server = new Server();
        server.start();

    }

}
